#include "pch.hpp"

// We want to include that file without the nasty defines
// so we can actually define the member functions
#define LOGGER_NO_DEFINES
#include "stream.hpp"

using namespace logger;




const QString stream::SERVICE_NAME = __STR__(stream);




stream::stream(boost::shared_ptr<const services::provider> p)
	: service(p)
{
	#ifdef _DEBUG
		m_levels[entry::exception] = true;
		m_levels[entry::error]     = true;
		m_levels[entry::warning]   = true;
		m_levels[entry::info]      = true;
		m_levels[entry::debug]     = true;
	#else
		m_levels[entry::exception] = true;
		m_levels[entry::error]     = true;
		m_levels[entry::warning]   = true;
		m_levels[entry::info]      = false;
		m_levels[entry::debug]     = false;
	#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////

stream::~stream()
{}
///////////////////////////////////////////////////////////////////////////////////////////////////




QString stream::name() const
{
	return SERVICE_NAME;
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void stream::log_detailed(entry::Level level, QString message, QString module, QString file, QString function, std::size_t line)
{
	*this << entry(level, message, module, file, function, line, 0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////




bool &stream::operator[](entry::Level lvl)
{
	return m_levels[lvl];
}
///////////////////////////////////////////////////////////////////////////////////////////////////

const bool &stream::operator[](entry::Level lvl) const
{
	logmap::const_iterator i = m_levels.find( lvl );

	if(i == m_levels.end())
		BOOSTEXT_THROW(boostext::invalid_value_exception(lvl));

	return *i;
}
///////////////////////////////////////////////////////////////////////////////////////////////////




const char* stream::formatLevel(entry::Level lvl) const
{
	switch(lvl)
	{
	case entry::exception: return "exception";
	case entry::error:     return "error";
	case entry::warning:   return "warning";
	case entry::info:      return "info";
	case entry::debug:     return "debug";
	default: BOOSTEXT_THROW(boostext::invalid_value_exception(lvl));
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
